﻿namespace dotnet_notes.Filters
{
    /// <summary>
    /// 全局 Action 异常过滤器
    /// </summary>
    public class GlobalExceptionFilter : IAsyncExceptionFilter
    {
        public Task OnExceptionAsync(ExceptionContext context)
        {
            var response = new ResponseResult
            {
                Success = false,
                Result = new
                {
                    context.Exception.Message,
                    Time = DateTime.Now
                }
            };

            context.Result = new ObjectResult(response);

            return Task.CompletedTask;
        }
    }
}
